<?php

namespace App\Services\Game\Data\Log;

use App\Services\Service;
use App\Services\Traits\DatabaseMysql;
use App\Models\Game\Log\Cost as Log;

class CostService extends Service
{
    use DatabaseMysql;

    /**
     * 获取数据列表
     *
     * @param \Illuminate\Http\Request $request
     * @return \Illuminate\Database\Eloquent\Collection[]|int[]
     */
    public function getList($request)
    {
        $query = Log::query();

        // 筛选【平台】
        $this->makeWhereParamOrg($request, $query);
        // 筛选【时间】
        $this->makeWhereParamDatetime($request, $query);
        // 筛选【币种】
        $this->makeWhereParam($request, 'currency', $query);
        // 筛选【类型】
        $this->makeWhereParam($request, 'cost_type', $query);
        // 筛选【搜索】
        $this->makeWhereParamSearch($request, $query);

        // 数据条数
        $total = (clone $query)->count();
        // 排序分页
        $this->makeOrderParam($request, $query)->makePaginationParam($request, $query);
        // 第二排序
        $this->makeOrderParam($request, $query, 'id');
        // 查询数据
        $collection = $query->with('org:code,name')->get();

        return [
            $collection,
            $total
        ];
    }
}
